/*
 * @Author: szx
 * @Date: 2021-12-24 15:15:57
 * @LastEditTime: 2021-12-24 15:30:09
 * @Description:
 * @FilePath: \leetcode\500-599\530\530.js
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var getMinimumDifference = function (root) {
    let pre = 0;
    let res = Infinity;
    flag = false;
    const dfs = (root) => {
        if (!root) return;
        dfs(root.left);
        if (flag) {
            if (root.val - pre < res) res = root.val - pre;
        } else {
            flag = true;
        }
        pre = root.val;
        dfs(root.right);
    };
    dfs(root);
    return res;
};
